﻿using System;
using MonoTouch.UIKit;
using MonoTouch.Foundation;
using MonoTouch.ObjCRuntime;
using System.Drawing;
using System.Collections.Generic;
namespace Beauty
{
	[Register("Iv_Product")]
	public partial class Iv_Product : UIView
	{	
		List<productItem> productCells;
		static NSString tableProductCellId = new NSString("tableCell");
		static NSString gridProductCellId = new NSString("gridCell");
		bool isGrid;
		public Iv_Product ()
		{
			productCells = new List<productItem> ();

			for (int i = 0; i < 12; i++) {
				var productItem = new productItem ();
				productCells.Add (productItem);
			}

			var arr = NSBundle.MainBundle.LoadNib("Iv_Product", this, null);
			var v = Runtime.GetNSObject(arr.ValueAt(0)) as UIView;
			v.Frame = new RectangleF(0, 0, Frame.Width, Frame.Height);
			AddSubview(v);
			 productCollection.Layer.BorderWidth = 1f;

			 productCollection.Layer.BorderColor = UIColorExtensions.FromHexString("#b2b2b2").CGColor;

			productCollection.Layer.CornerRadius = 5f;

			productCollection.RegisterClassForCell (typeof(productCell), gridProductCellId);
			productCollection.RegisterClassForCell (typeof(productCellList), tableProductCellId);
// 
			productCollection.SetCollectionViewLayout (new Iv_Layout (), true);
			productCollection.Source = new Iv_productCollectionSource (productCells ,0);

		} 
		public void changeLayout ()
		{
			if (!isGrid) {
				productCollection.SetCollectionViewLayout (new Iv_LayoutList (), false);
				productCollection.Source = new Iv_productCollectionSource (productCells, 1);

				isGrid = true;
			} else {
				productCollection.SetCollectionViewLayout (new Iv_Layout (), false);
				productCollection.Source = new Iv_productCollectionSource (productCells, 0);

				isGrid = false;
			}
		}
	}
}

